﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class GetJsapi_ticketDAL
    {
#pragma warning disable CS0618 // “ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”
        string Conn = ConfigurationSettings.AppSettings["con"].ToString();
#pragma warning restore CS0618 // “ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”
        /// <summary>
        /// 从数据库获取Jsapi_ticket
        /// </summary>
        /// <returns></returns>
        public string getJsTicket()
        {
            SqlConnection con = new SqlConnection(Conn);
            SqlCommand cmd = new SqlCommand("verifyJsticket", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            con.Open();
            string ticket = cmd.ExecuteScalar().ToString();
            con.Close();
            return ticket;
        }

        //更新存储Jsapi_ticket
        public int updateJsTicket(string expires_in, string ticket)
        {
            SqlParameter[] sp = new SqlParameter[] { 
                new SqlParameter("@expires_in",expires_in),
                new SqlParameter("@ticket",ticket)
            };
            string sqlstr = "update jsapi_ticket set expires_in = @expires_in,ticket = @ticket,createtime = getdate() where id = 1";
            int i = SqlHelper.ExecuteNonQuery(Conn, CommandType.Text, sqlstr, sp);
            return i;
        }
    }
}
